package com.mmm.user.controller;

import com.mmm.common.vo.SuccessVo;
import com.mmm.user.dao.DeliveryDao;
import com.mmm.user.entity.University;
import com.mmm.user.service.UniversityService;
import com.mmm.user.vo.UniversityPureVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * (University)表控制层
 *
 * @author One
 * @since 2022-02-25 15:49:34
 */
@RestController
@RequestMapping("/university")
public class UniversityController {
    /**
     * 服务对象
     */
    @Resource
    private UniversityService universityService;
    @Resource
    private DeliveryDao deliveryDao;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    public SuccessVo<University> selectOne(@PathVariable Long id) {
        return new SuccessVo<>(this.universityService.esById(id));
    }

    @PutMapping("/put")
    public SuccessVo<University> insert(@RequestBody University university) {
        return new SuccessVo<>(1,universityService.insert(university));
    }

    @PostMapping("/update")
    public SuccessVo<University> update(@RequestBody University university) {
        return new SuccessVo<>(3,universityService.update(university)) ;
    }

    @DeleteMapping("/delete/{id}")
    public SuccessVo<Boolean> deleteById(@PathVariable Long id) {
        return new SuccessVo<>(2,universityService.deleteById(id)) ;
    }

    @GetMapping("/list")
    public SuccessVo<com.mmm.common.vo.Paging<UniversityPureVo>> list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer size) {
        List<UniversityPureVo> uList=new ArrayList<>();
        List<DeliveryDao> dList=new ArrayList<>();
        return  new SuccessVo<>(this.universityService.list(page, size)) ;
    }
}